#ifndef __MY_PID_H_
#define __MY_PID_H_

#define Safe_div(numerator, denominator, zero) ((denominator == 0) ? (zero) : ((numerator) / (denominator)))//��ĸ��Ϊ0
#define Limit( x,min,max ) ( ((x) <= (min)) ? (min) : ( ((x) > (max))? (max) : (x) ) ) //�޷�

typedef struct
{
  float Kp;   //����ϵ��
  float Ki;   //����ϵ��
  float Kd_expect;//΢��ϵ��
  float Kd_feedback;//΢������
  float K_ff; //ǰ��
  
  float err;
	float expect_old;    
	float feedback_old; 
  
  float expect_d;      //Ŀ��΢��
  float feedback_d;    //ʵ��΢��
    
  float err_i;   //����
  float out;     //PID���  
}PID_DATA;
void PID_Calculate(float expect,float feedback,float feedforward,float dT,PID_DATA *PID,float ierr_Limit,float i_Limit);

void my_PID_Init(void);
void User_my_yaw_PID_Init(void);
extern PID_DATA centre_xy[6];
extern PID_DATA my_yaw_arg[4];
void PID_Calculate_Car_left(int Speed_goal,int Speed_now);
void PID_Calculate_Car_right(int Speed_goal,int Speed_now);
void  PID_Calculate_Car(int Speed_goal_left,int Speed_goal_right);
#endif
